for n = 1 : 6
    H = hilb(n + 1);
    r1 = (-1).^(0 : n);
    r2 = zeros(1, n + 1);
    for j = 0 : n
        for i = 1 : j
            r2(j + 1) = r2(j + 1) + (-1) ^ (i + j) / i;
        end    
    end
    beta = g_s(H, r1');
    gamma = g_s(H, r2');

    
    alpha = beta * log(2) + gamma;

    
    disp('n:');
    disp(n);
    disp('beta:');
    disp(beta);
    disp('gamma');
    disp(gamma);
    disp('alpha:');
    disp(alpha);
end
disp('第四问令ln2=0.69315的α：');
for n = 1 : 6
    H = hilb(n + 1);
    r1 = (-1).^(0 : n);
    r2 = zeros(1, n + 1);
    for j = 0 : n
        for i = 1 : j
            r2(j + 1) = r2(j + 1) + (-1) ^ (i + j) / i;
        end    
    end
    beta = g_s(H, r1');
    gamma = g_s(H, r2');
    alpha = beta * 0.69315 + gamma;
    disp('n:');
    disp(n);
    disp('alpha:');
    disp(alpha);
    cH = cond(H);
    disp('condH:');
    disp(cH);
end

a = 1e-10;
disp('Tikhonov正则化的α：');
for n = 1 : 6
    H = hilb(n + 1);
    r1 = (-1).^(0 : n);
    r2 = zeros(1, n + 1);

    for j = 0 : n
        for i = 1 : j
            r2(j + 1) = r2(j + 1) + (-1) ^(i + j) / i;
        end    
    end
    r = r1 * log(2) + r2;
    I = eye(size(H' * H));
    alpha = (H' * H + a * I) \ (H' * r');
    
    disp('n:');
    disp(n);
    disp('alpha:');
    disp(alpha');
end